package com.campus.client.controller;

import com.campus.client.net.ClientConnector;
import com.campus.client.view.StudentMainFrame;
import com.campus.common.message.StudentRegisterResponse;
import com.campus.common.vo.Student;

import javax.swing.*;
        import java.awt.*;
        import java.io.IOException;

public class StudentMainController extends Component {
    private StudentMainFrame studentMainFrame;
    private ClientConnector connector;

    public StudentMainController(StudentMainFrame studentMainFrame, ClientConnector connector) {
        this.studentMainFrame = studentMainFrame;
        this.connector = connector;
        setupEventHandlers();
    }

    private void setupEventHandlers() {
        // 设置登录按钮事件
        studentMainFrame.setChangePasswordButtonAction(event -> {
            try {
                studentMainFrame.showPasswordChangeFrame();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        });

        studentMainFrame.setLogoutButtonAction(event -> {

            try {
                JOptionPane.showMessageDialog(this,
                        "已退出登录",
                        "退出登录",
                        JOptionPane.INFORMATION_MESSAGE);
                studentMainFrame.showLoginFrame();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

        });

        studentMainFrame.setStoreButtonAction(event -> {
            try {
                studentMainFrame.showShopFrame();
            }  catch (Exception e) {
                throw new RuntimeException(e);
            }
        });

        studentMainFrame.setLibraryButtonAction(event -> {
            try {
                studentMainFrame.showLibraryFrame();
            }  catch (Exception e) {
                throw new RuntimeException(e);
            }
        });

        studentMainFrame.setBankButtonAction(event -> {
            try {
                studentMainFrame.showBankFrame();
            }  catch (Exception e) {
                throw new RuntimeException(e);
            }
        });

        studentMainFrame.setCourseSelectionButtonAction(event -> {
            try {
                studentMainFrame.showStudentCourseFrame();
            }  catch (Exception e) {
                throw new RuntimeException(e);
            }
        });

        studentMainFrame.setStudentInfoButtonAction(event -> {
            try {
                studentMainFrame.showStudentInfoFrame();
            }  catch (Exception e) {
                throw new RuntimeException(e);
            }
        });


    }

}